//
// Created by francklinson on 2021/8/22 AT 10:11.
//
#include <iostream>
#include <vector>
#include <unordered_map>
#include <queue>
#include <algorithm>
#include <functional>
#include <climits>

using namespace std;

class Solution {
public:
    bool escapeGhosts(vector<vector<int>> &ghosts, vector<int> &target) {
        if (target[0] == 0 and target[1] == 0)
            return true;
        vector<int> source{0, 0};
        int dis = distance(source, target);
        for (vector<int> &ghost:ghosts) {
            if (distance(ghost, target) <= dis)
                return false;
        }
        return true;
    }

    int distance(vector<int> &pos, vector<int> &target) {
        return abs(pos[0] - target[0]) + abs(pos[1] - target[1]);
    }
};

class Solution2 {  // 最快题解
public:
    bool escapeGhosts(vector<vector<int>> &ghosts, vector<int> &target) {
        int distance1 = abs(target[0]) + abs(target[1]);

        int distance2 = INT_MAX;
        for (const auto &ghost :ghosts) {
            distance2 = min(distance2, abs(ghost[0] - target[0]) + abs(ghost[1] - target[1]));
        }

        return distance1 < distance2;
    }
};

int main() {
    vector<vector<int>> ghosts{{1, 0},
                               {0, 3}};
    vector<int> target{0, 1};
    Solution solution;
    cout << solution.escapeGhosts(ghosts, target) << endl;
    return 0;
}

